import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# 实例化驱动
browser = webdriver.Chrome()
# 打开网页
browser.get('https://www.baidu.com/')
# 全屏化
browser.maximize_window()
# 设置隐式等待
browser.implicitly_wait(15)
# 获取设置定位元素   //*[text()='设置']
WebDriverWait(browser,10,0.5).until(EC.presence_of_element_located((By.ID,"s-usersetting-top"))).click()
# 点击搜索设置
WebDriverWait(browser,10,0.5).until(EC.presence_of_element_located((By.XPATH,"//*[text()='搜索设置']"))).click()
time.sleep(2)       # 等待弹窗弹出
# 点击保存设置
WebDriverWait(browser,10,0.5).until(EC.presence_of_element_located((By.XPATH,"//*[text()='保存设置']"))).click()
time.sleep(3)
# alert弹窗处理
alert = browser.switch_to.alert
# 点击确定
alert.accept()

# 弹窗中点击取消
# alert.dismiss()

time.sleep(10)

